#include "stdafx.h"
#include "MagicRun.h"
#include "WowFunc.h"


LPVOID CMagicRun::m_data = 0;
E_MAGIC CMagicRun::m_eType = E_NONE;

bool CMagicRun::Init()
{
    if (m_hook) return 0;
    m_hook = SetWindowsHookEx(WH_CALLWNDPROCRET, CMagicRun::CallWndRetProc, 0, CWowFunc::m_hThreadWowID);
    DWORD dd = GetLastError();
    return true;
}

bool CMagicRun::Release()
{
    if (m_hook)
    {
        UnhookWindowsHookEx(m_hook);
        m_hook = 0;
        m_eType = E_NONE;
    }
    return 0;
}

bool CMagicRun::Run(E_MAGIC et, LPVOID pdata, HWND hwnd)
{
    m_data = pdata;
    m_eType = et;
    ::SendMessage(CWowFunc::m_hWndWow, WM_MBUTTONUP,0,0);
    m_eType = E_NONE;
    m_data = 0;
    Sleep(1291);
    return 0;
}

//::SendMessage(m_hWndWow, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(m_KeyPoint.x,m_KeyPoint.y));
LRESULT CALLBACK CMagicRun::CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0 || !m_data) return CallNextHookEx(0, nCode, wParam, lParam);
    
    switch(m_eType)
    {
    case E_LOOT:
        {
            WOW_GUID* ptmp = (WOW_GUID*)m_data;
            CWowFunc::TheLoot(ptmp->low, ptmp->high);
        }
    }
    return CallNextHookEx(0, nCode, wParam, lParam);
}